textiter: small optimization for find_by_log_attrs()
authorSébastien Wilmet <swilmet@gnome.org>
Fri, 11 Apr 2014 11:41:50 +0000 (13:41 +0200)
committerSébastien Wilmet <swilmet@gnome.org>
Sun, 13 Jul 2014 15:08:52 +0000 (17:08 +0200)
Use gtk_text_iter_set_line_offset (&tmp_iter, 0) instead of
gtk_text_iter_get_line(). The difference should not be big. In the first
case the line doesn't need to be traversed thanks to the offset 0. For
get_line(), the btree must be traversed.

A temporary iter is needed to not break the behavior. But the behavior
is quite strange, the function works directly on the iter passed as an
argument to the function, even if the function returns FALSE (not
found). So maybe a later commit will fix this strange behavior.

https://bugzilla.gnome.org/show_bug.cgi?id=629129

gtk/gtktextiter.c

index a97dea44efa447eaf79d03f9d5e51ec86971a3d6..f445240e09c6987f084866cf2ffef77c1e4dae53 100644 (file)
@@ -3131,14 +3131,18 @@ find_by_log_attrs (GtkTextIter     *iter,
         }
       else
         {
-          /* TODO optimize this part */
-          /* go to end of previous line. need to check that
-           * line is > 0 because backward_line snaps to start of
-           * line 0 if it's on line 0
+          GtkTextIter tmp_iter = *iter;
+
+          /* Go to end of previous line. First go to the current line offset 0,
+           * because backward_line() snaps to start of line 0 if iter is already
+           * on line 0.
            */
-          if (gtk_text_iter_get_line (iter) > 0 &&
-              gtk_text_iter_backward_line (iter))
+          gtk_text_iter_set_line_offset (&tmp_iter, 0);
+
+          if (gtk_text_iter_backward_line (&tmp_iter))
             {
+              *iter = tmp_iter;
+
               if (!gtk_text_iter_ends_line (iter))
                 gtk_text_iter_forward_to_line_end (iter);